package com.bw.ai.controller;

import com.bw.ai.domain.Doctor;
import com.bw.ai.mapper.AiMapper;
import com.bw.ai.service.VectorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/vectors")
public class VectorController {
    @Autowired
    private VectorService vectorService;
    @Autowired
    private AiMapper aiMapper;
    // 存储向量
    @PostMapping("/store")
    public ResponseEntity<Void> storeVector(@RequestBody Map<String, List<Doctor>> requestBody) {
        System.out.println(requestBody);
        List<Doctor> list = aiMapper.list();
        String key = requestBody.keySet().iterator().next();
        vectorService.storeVector(key, list);
        return ResponseEntity.ok().build();
    }

    // 查询相似向量
    @GetMapping("/search")
    public ResponseEntity<List<String>> similaritySearch(@RequestParam double[] queryVector, @RequestParam int k) {
        List<String> similarKeys = vectorService.similaritySearch(queryVector, k);
        return ResponseEntity.ok(similarKeys);
    }

}
